<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>资源监控平台</title>
    <link rel="stylesheet" href="./plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="./plugins/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="./css/app.css" media="all" />
    <link rel="stylesheet" href="./css/themes/default.css" media="all" id="skin" kit-skin />
    <link rel="stylesheet" href="./css/rmp.css" media="all" />
</head>

<body class="kit-theme">
<div class="layui-layout layui-layout-admin kit-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">资源监控平台RMP v2.0</div>
        <div class="layui-logo kit-logo-mobile">RMP</div>
        <ul class="layui-nav layui-layout-left kit-nav">
            <li class="layui-nav-item"><a href="./files/newRmpUtil.rar" target="_blank">离线工具</a></li>            
            <li class="layui-nav-item"><a href="javascript:;">反馈</a></li>
            <li class="layui-nav-item"><a href="javascript:;">关于</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其他系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="../rmp_old" target="_blank">资源监控系统_老版</a></dd>
                    <dd><a href="../atp" target="_blank">接口自动化测试平台</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right kit-nav">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <i class="layui-icon">&#xe63f;</i> 皮肤
                </a>
                <dl class="layui-nav-child skin">
                    <dd><a href="javascript:;" data-skin="default" style="color:#393D49;"><i class="layui-icon">&#xe658;</i> 默认</a></dd>
                    <dd><a href="javascript:;" data-skin="orange" style="color:#ff6700;"><i class="layui-icon">&#xe658;</i> 橘子橙</a></dd>
                    <dd><a href="javascript:;" data-skin="green" style="color:#00a65a;"><i class="layui-icon">&#xe658;</i> 原谅绿</a></dd>
                    <dd><a href="javascript:;" data-skin="pink" style="color:#FA6086;"><i class="layui-icon">&#xe658;</i> 少女粉</a></dd>
                    <dd><a href="javascript:;" data-skin="blue.1" style="color:#00c0ef;"><i class="layui-icon">&#xe658;</i> 天空蓝</a></dd>
                    <dd><a href="javascript:;" data-skin="red" style="color:#dd4b39;"><i class="layui-icon">&#xe658;</i> 枫叶红</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="./images/szsm.png" class="layui-nav-img"> 
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" id="view-user-space"><span>查看用户空间</span></a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="javascript:;" id="logout"><i class="fa fa-sign-out" aria-hidden="true"></i>注销</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black kit-side">
        <div class="layui-side-scroll">
            <div class="kit-side-fold"><i class="fa fa-navicon" aria-hidden="true"></i></div>
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="kitNavbar" kit-navbar>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;"><i class="layui-icon">&#xe62c;</i> <span>&nbsp;&nbsp;资源监控</span></a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;" data-url="html/monitoring/monitoring.html" data-icon="fa-desktop" data-title="监控视图" kit-target data-id='2'><i class="fa fa-desktop" aria-hidden="true"></i><span> 监控视图</span></a>
                        </dd>
                        <dd>
                            <a href="javascript:;" data-url="html/monitoring/serverInfo.html" data-icon="fa-server" data-title="服务器" kit-target data-id='3'><i class="fa fa-server" aria-hidden="true"></i><span> 服务器</span></a>
                        </dd>
                        <dd>
                            <a href="javascript:;" data-url="html/monitoring/setting.html" data-icon="fa-gears" data-title="配置选项" kit-target data-id='4'><i class="fa fa-gears" aria-hidden="true"></i><span> 配置选项</span></a>
                        </dd>
                        <dd>
                            <a href="javascript:;" data-url="html/monitoring/report.html" data-icon="fa-bar-chart" data-title="报表记录" kit-target data-id='5'><i class="fa fa-bar-chart" aria-hidden="true"></i><span> 报表记录</span></a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="" href="javascript:;"><i class="layui-icon">&#xe631;</i> <span>&nbsp;&nbsp;工具箱</span></a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;" data-url="html/util/dataApi.html" data-icon="fa-plug" data-title="非功能测试需求" kit-target data-id='6'><i class="fa fa-plug" aria-hidden="true"></i><span> 非功能测试需求</span></a>
                        </dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body" id="container" data-url="html/main.html">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;"><i class="layui-icon layui-anim layui-anim-rotate layui-anim-loop">&#xe63e;</i> 请稍等...</div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        2017 &copy;
        <a href="http://kit.zhengjinfan.cn/" target="_blank">kitAdmin</a> for Resource Monitoring Platform
    </div>
</div>
<div id="templates"></div>
<script src="./plugins/jquery.js"></script>
<script src="./plugins/layui/layui.js"></script>
<script src="./js/global.js"></script>
<script>
    var userKey;
    var userSetting;
    var message;
    var templates = {};
    var rmputils;
    layui.config({
        base: './js/ext/'
    }).use(['app', 'layer', 'laytpl', 'message', 'rmputils'], function() {
        var app = layui.app,
            laytpl = layui.laytpl,
            layer = layui.layer;
        rmputils = layui.rmputils;
        message = layui.message;
        
        console.log('添加userKey:addUserKey(要添加的userKry);');
        
        //主入口
        app.set({
            type: 'iframe'
        }).init();

        //获取本地是否已存在userKey
        var rmpTable = layui.data('rmp');
        rmpTable != null && (userKey = rmpTable.userKey);
        if (userKey != null) {
            validateUserKey(userKey);
        } else {
            window.location.href='./login.html';
        }

        //获取用户设置选项
        $.post(GET_USER_SPACE_SETTING_URL, {userKey:userKey}, function(json){
            validatReturnJson(json, function(){
                userSetting = json.data;
            });
        });

        //初始化系统所有模板
        var loadindex = layer.msg('正在初始化...', {icon:16, shade:0.4, time:999999});

        $("#templates").load('./html/template/commonTemplate.html', function(){
            $("#templates").children('script').each(function(i, n){
                templates[$(n).attr('id')] = $(n).attr('render-html') != undefined ? laytpl($(n).html()).render({}) : laytpl($(n).html());
            });
            $("#view-user-space").on('click', function(){
                $.post(LIST_USER_SPACE_INFO_URL, {userKey:userKey}, function(json){
                    validatReturnJson(json, function(){
                        layer_show('查看用户空间', templates["show-userKey-table"].render(json.data), 700, 400, 1);
                    })
                });
            });
            $(".layui-layout-left > li > a:eq(2)").on('click', function(){
                layer_show('关于', templates["rmp-about-page"], 410, 180, 1, null, null, null, {
                    skin: 'layui-layer-demo', //样式类名
                    closeBtn: 0, //不显示关闭按钮
                    anim: 2
                });
            });

            layer.close(loadindex);
        });

        $(document).delegates({
            '.change-user-key':function(){//更改用户空间
            	var that = this;
                layer.confirm('确认切换该用户空间吗?<br><span style="color:red;">切换之后本地监控数据将会清除,同时相关设置也会切换到该空间下!</span>', {title:'警告', icon:0}, function(index){
                    layer.close(index);                   
                    $.post(VALIDATE_USER_KEY_URL, {userKey:$(that).attr('id')}, function(json){
                        validatReturnJson(json, function(){
                            userKey = json.data.userKey;
                            layui.data('rmp', {
                                key:'userKey',
                                value:userKey
                            });
                            window.location.reload();
                            layer.closeAll('page');
                            layer.msg('切换成功,请查看控制台数据!', {time:1800});
                        })
                    });
                });
            },
            '#logout':function(){//登出
                layer.confirm('确认登出吗?', {title:'警告', icon:0}, function(index){
                    //清除userKey
                    layui.data('rmp', {
                        key:'userKey',
                        remove:true
                    });
                    window.location.href = 'login.html';
                });
            },
            '.layui-layout-left > li > a:eq(1)':function() {
            	layer.alert('对不起,由于你长得太丑,开发者已禁止你进行反馈!', {icon:0, title:'友善的提醒'});
            },
            'dl.skin > dd':function(){
                var $that = $(this);
                var skin = $that.children('a').data('skin');
                switchSkin(skin);
            }
        });

        var setSkin = function(value) {
                    layui.data('kit_skin', {
                        key: 'skin',
                        value: value
                    });
                },
                getSkinName = function() {
                    return layui.data('kit_skin').skin;
                },
                switchSkin = function(value) {
                    var _target = $('link[kit-skin]')[0];
                    _target.href = _target.href.substring(0, _target.href.lastIndexOf('/') + 1) + value + _target.href.substring(_target.href.lastIndexOf('.'));
                    setSkin(value);
                },
                initSkin = function() {
                    var skin = getSkinName();
                    switchSkin(skin === undefined ? 'default' : skin);
                }();
    });
    
    function addUserKey(userKey) {
    	$.post(USER_SPACE_ADD_KEY_URL, {userKey:userKey}, function(json) {
    		console.log(json.msg);
    	});
    }
</script>
</body>

</html>